package com.whitesalt.inputfix;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import javax.swing.*;


/**
 * @ White_Salt
 * 创建于 2017/10/14
 * powered by: IntelliJ IDEA
 */
public class InputFix extends JavaPlugin
{

    private GUI Gui;

    public InputFix()
    {
        AsynCommand.setPlugin(this);
    }

    @Override
    public void onEnable()
    {
        String logo = "[InputFix] ";
        Bukkit.getConsoleSender().sendMessage(logo + "启用……");

        saveDefaultConfig();

        OpenGUI();
    }

    private void OpenGUI()
    {
        new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                Gui = new GUI();

                SettingTitle dialog;
                if (getConfig().getString("WindowTitle").equals(""))
                {
                    dialog = new SettingTitle();
                    dialog.pack();
                    dialog.setVisible(true);

                    getConfig().set("WindowTitle", dialog.Title.getText());
                    saveConfig();
                }

                JFrame frame = new JFrame(getConfig().getString("WindowTitle"));
                frame.setContentPane(Gui.mainPanel);
                frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.pack();
                frame.setVisible(true);
            }
        }
        ).start();
    }


}
